package com.main.hotel.service.impl;

import com.main.hotel.entity.CustomerToken;
import com.main.hotel.repository.CustomerTokenRepository;
import com.main.hotel.service.CustomerTokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CustomerTokenServiceImpl implements CustomerTokenService {
  @Autowired
  private CustomerTokenRepository customerTokenRepository;
  @Override
  public void addToken(CustomerToken customerToken) {
    customerTokenRepository.save(customerToken);
  }

  @Override
  public void updataToken(CustomerToken customerToken) {
    CustomerToken customerToken1 =findByCustomerId(customerToken.getCustomer_id());
    customerToken1.setBuild_time(customerToken.getBuild_time());
    customerToken1.setToken(customerToken.getToken());
    customerTokenRepository.save(customerToken1);
  }

  @Override
  public CustomerToken findByCustomerId(int customer_id) {
    CustomerToken customerToken=customerTokenRepository.findByCustomerId(customer_id);

    return customerToken;
  }
}
